import { reqGoodsInfo ,reqAddOrUpdateShopCart} from "@/api"
import { getUUID } from "@/utils/uuid_token";
export default ({
    state:{
        goodInfo:{},
        uuid_token:getUUID()
    },
    mutations:{
        GETGOODINFO(state,goodInfo){
            state.goodInfo=goodInfo;
        }
    },
    actions:{
        async getGoodInfo({commit},skuId){
            let result= await reqGoodsInfo(skuId)
            if(result.code==200){
                commit("GETGOODINFO",result.data);
                console.log('getGoodInfo',result.data);
            }
        },
        async addOrUpdateShopCart({commit},{skuId,skuNum}){
            let result=await reqAddOrUpdateShopCart(skuId,skuNum);
            if(result.code==200){
                console.log("更新成功");
                return 'ok';
                
            }else{
                return Promise.reject(new Error('faile'));
            }
        }
    },
    getters:{
        categoryView(state){
            return state.goodInfo.categoryView||{};
        },
        // 简化产品信息的数据
        skuInfo(state){
            return state.goodInfo.skuInfo||{};
        },
        // 产品售卖属性的简化
        spuSaleAttrList(state){
            return state.goodInfo.spuSaleAttrList || []
        }
    }
})